<template>
	<view class="container">
		<view style='margin: 20px;'>
			<qrcode :val="qrval" :size="qrsize" ref="qrcode"></qrcode>
		</view>
		<image class="img" v-if="imageSrc" :src="imageSrc" mode="center" />
		<button type="primary" @tap="downloadImage">下载</button>
	</view>
</template>
<script>
	import qrcode from '../../components/qrcode/qrcode.vue'
	export default {
		data() {
			return {
				title: '二维码生成',
				name: '诗小柒',
				showClearIcon: false,
				qrval: 'www.baidu.com',
				qrsize: 100,
				imageSrc: ''
			}
		},
		onUnload() {
			this.imageSrc = '';
		},
		mounted() {
			this.creatQrcode()
		},
		methods: {
			creatQrcode() {
				this.$refs.qrcode.creatQrcode();
			},
			downloadImage: function () {
				uni.showLoading({
					title:'下载中'
				})
				var self = this
				uni.downloadFile({
					url: "",
					success: (res) => {
						console.log('downloadFile success, res is', res)
						self.imageSrc = res.tempFilePath;
						uni.hideLoading();
					},
					fail: (err) => {
						console.log('downloadFile fail, err is:', err)
					}
				})
			}
		},
		components: {
			qrcode
		}
	}
</script>
